<!-- 订单调整头部详情 -->
<template>
  <div class="order-msg flex">
    <i class="iconfont order-img icon-icon_list1">&#xe61f;</i>
    <div class="order-content flex flex-horizontal-between">
      <ul class="item_warp flex flex-wrap flex-horizontal-between">
        <li class="flex flex-vertical-center" v-for="(item,index) in msgList" :key="index">
          <p>{{item.name}}:</p>
          <p>{{baseMsg[item.key]}}</p>
        </li>
      </ul>
      <div class="order-status">
        <div class="flex flex-vertical-center">
          <p v-if="baseMsg.statusStr">调整({{baseMsg.statusStr}})</p>
          <Button type="primary" style="margin-left:20px" v-if="showExamineFun('1')"
            @click="onEdit">编辑</Button>
          <Button type="primary" style="margin-left:20px" v-if="showExamineFun('2')"
            @click="onRepeal">撤销调整</Button>
          <Button type="primary" style="margin-left:20px" v-if="showExamineFun('3')"
            @click="onAudit">审核</Button>
        </div>
      </div>
    </div>
    <!--审核-->
    <audit-modal ref="audit" :isGogoPrve='false' @auditSuccess='auditSuccess' />
  </div>
</template>
<script>
  import auditModal from '@/components/biz/audit/audit-modal.vue'
  import auditMgr from '@/biz/flowApproval/processAudit.js'
  export default {
    components: { auditModal },
    data() {
      return {
        loading: false,
        orderStatusName: this.$route.query.orderType,
        msgList: [{
          name: `${this.$route.query.orderType}调整单编号`,
          key: 'adjustNo',
        },
        {
          name: '申请人',
          key: 'applyName',
        },
        {
          name: '申请日期',
          key: 'applyTime',
        },
        {
          name: '审核日期',
          key: 'auditTime',
        }],
        baseMsg: {},
      }
    },
    methods: {
      show(data) {
        this.baseMsg = { ...data }
        this.baseMsg.applyTime = this.$dt.tool.formatterDate(this.baseMsg.applyTime)
        this.baseMsg.auditTime = this.$dt.tool.formatterDate(this.baseMsg.auditTime)
      },
      showExamineFun(flag) {
        let type = this.orderStatusName
        console.log(type, 'typetype')
        let isBuildCase = this.$route.meta.isbuild == 'nobuildpage' ? true : false
        let isflag = this.$route.query.isflag == 'edit' ? true : false
        switch (flag) {
          case '1': //编辑
            return this.baseMsg.status == 'UNSUBSTITUTED' && !isBuildCase && ((type == '认购' &&
              this.unlocking('0104010404')) || (type == '签约' && this.unlocking(
              '0104030404')))
          case '2': //撤销
            return this.baseMsg.status == 'APPROVAL' && !isBuildCase && ((type == '认购' &&
              this.unlocking('0104010403')) || (type == '签约' && this.unlocking(
              '0104030403')))
          case '3': //审批
            return this.baseMsg.status == 'APPROVAL' && isflag && isBuildCase &&
              ((type == '认购' && this.unlocking('0206090101')) || (type == '签约' &&
                this.unlocking('0206090201')))
          default:
            break
        }
      },
      success() {
        this.$emit('success')
      },
      //编辑
      onEdit() {
        this.$router.push({
          name: (this.orderStatusName == '认购') ? 'subAdjust' : 'conAdjust',
          query: {
            adjustmentId: this.$route.query.adjustmentId
          }
        })
      },
      //撤销调整
      onRepeal() {
        this.$Modal.confirm({
          title: `撤回“${this.orderStatusName}调整”审核确认`,
          content: `请确认，是否撤回当前“${this.orderStatusName}调整”？撤回后，您可在编辑“${this.orderStatusName}调整单”页面中重新发起审核`,
          okText: '确认撤回',
          onOk: () => {
            let params = {
              auditType: (this.orderStatusName == '认购') ? 10 : 11,
              businessId: this.$route.query.adjustmentId,
            }
            auditMgr.back(params).then((res) => {
              this.$Message.success('撤销成功')
              this.success()
            })
          }
        })
      },
      // 审核
      onAudit() {
        this.$refs.audit.show({
          auditId: this.$route.query.auditId,
          businessId: this.baseMsg.businessId,
          auditType: this.orderStatusName == '认购' ? 10 : 11,
          picList: [],
          fileList: []
        })
      },
      //审核通过
      auditSuccess() {
        this.success()
      }
    },
  }
</script>
<style lang="scss" scoped>
  .order-msg {
    padding: 10px 30px;
    width: 100%;
    background-color: #f2f2f2;

    .order-content {
      width: 100%;
      background-color: #f2f2f2;
      font-size: 18px;

      .item_warp {
        flex: 1;
        padding-right: 5%;
      }
    }

    .order-img {
      margin: 15px 0;
      width: 30px;
      height: 30px;
      color: #0f42a7;
      font-size: 20px;
    }

    .back-img {
      margin: auto 0;
      width: 80px;
      height: 64px;
    }

    .order-status {
      display: flex;
      position: relative;
      padding-left: 3%;
      min-width: 20%;
      border-left: 1px solid #d7d7d7;
      font-size: 18px;
    }

    .tips {
      position: absolute;
      bottom: 5px;
      background-color: rgba(254, 252, 236, 1);
      font-size: 14px;
      padding: 0 5px;
      height: 32px;
      line-height: 32px;
      text-align: center;

      span {
        color: #2d8cf0;
        border-bottom: 1px solid #2d8cf0;
        cursor: pointer;
      }
    }
  }
</style>